package com.jz.pay3.controller;

import com.jz.commom.api.dto.request.Payment;
import com.jz.commom.api.dto.response.CommonResult;
import com.jz.pay3.service.PaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@Slf4j
@Api
@ApiModel(value = "支付接口")
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @ApiOperation(value = "创建订单")
    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int result = paymentService.create(payment);
        log.info("*** 插入结果："+result);
        if(result>0){
            return CommonResult.success("ok","");
        }else{
            return CommonResult.fail("插入失败","");
        }
    }

    @ApiOperation(value = "根据ID查询订单")
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        Payment result = paymentService.getPaymentById(id);
        log.info("*** 查询结果："+result);
        if(ObjectUtils.isEmpty(result)){
            return CommonResult.fail("查询无对应数据",null);
        }else{
            return CommonResult.success(result);
        }
    }


    /**
     * testSentinel
     * @return CommonResult
     */
    @ApiOperation(value = "testSentinel")
    @GetMapping(value = "/payment/testSentinel")
    public CommonResult testSentinel(){
        return CommonResult.success("ok1",new Date());
    }

}
